<template>
  <a-modal :width="modalWidth"
           :title="title"
           :visible.sync="visible"
           @cancel="handleClose">
    <template slot="footer">
      <a-button key="back" @click="handleClose">
        关闭
      </a-button>
    </template>
      <div>
        <k-form-build v-if="this.formType=='zdybd'"
          :value="jsonData"
          ref="KFB"
          :disabled="disabled"
        />
        <component v-if="this.formType=='wbbd'" :is="routeFormComponent"  :dataId="dataId"
                   :disabled="disabled"></component>
      </div>

  </a-modal>
</template>

<script>
  import {METHOD, removeAuthorization, request} from '@/utils/request'
  import {postAction, putAction} from '@/api/manage'
  import {getBpmForm,getBpmFormData} from '@/api/api'

  export default {
        name: 'FormModelGet',
        data () {
            return {
              modalWidth:800,
              title:"表单数据",
              visible: false,
              param:{},
              tableId:"",
              model: {},
              disabled:true,
              jsonData: {
              },
              formType:"",
              routeUrl:"",
              dataId:"",
              routeFormComponent:"",
            }
        },
        methods: {
          view(param) {
            this.formType=param.formType;
            this.routeUrl=param.routeUrl;
            this.dataId=param.dataId;
            let that = this;
            that.visible = true;
            that.param = Object.assign({}, param);
            that.$nextTick(() => {
              if(that.formType=='wbbd'){
                var myComponent =() => import("@/views/"+that.routeUrl);
                that.routeFormComponent = myComponent;
              } if(that.formType=='zdybd'){
                that.initFormView(that.param.formId);
                that.initFormData(that.param.dataId,that.param.formId);
              }
            });
          },
          initFormView(formId) {
            getBpmForm({
              id: formId
            }).then((res) => {
              let jsonData=res.result.html;
              this.tableId=res.result.tableId;
              if (jsonData) {
                let jData=JSON.parse(jsonData);
                this.jsonData=jData;
              }
            })
          },
          initFormData(dataId,formId){
            let that = this;
            getBpmFormData({
              dataId: dataId,
              formId: formId
            }).then((res) => {
              const oldData=res.result;
              if(oldData){
                that.model=oldData;
                this.$refs.KFB.setData(oldData)
              }
            })
          },
          handleClose() {
            this.visible = false;
          },
        },
    }
</script>